﻿#
import os
import inspect
import sys
from datetime import datetime,date,time
import re

MajorVersion=0
MinorVersion=1
MaintenanceVersion=0
BuildNumber=''
BuildDateSignature=''
PublishType=0	#	0:Preview	1:Alpha	2:Beta	3:Release

def execCmd(cmd):
	r=os.popen(cmd)
	text=r.read()
	r.close()
	return text

def	getVersionNumber():
	s=execCmd("svn info")	
	versionTag='Revision: '
	re_str=versionTag+'[0-9]+'
	rep=re.compile(re_str)
	m=rep.search(s)
	s=m.group()
	return s[len(versionTag):]

cur_path=os.path.dirname(sys.argv[0])
os.chdir(cur_path)

BuildNumber=getVersionNumber()

tm=datetime.utcnow()
BuildDateSignature=tm.strftime('%Y%m%d%H%M%S%f')

folder=os.path.join(os.path.split(cur_path)[0],'trueMotion')
rc_path=os.path.join(os.path.join(folder,'res'),'TrueMotion.rc2')

rc_file=open(rc_path, 'r')
lines=rc_file.readlines()
rc_file.close()

if PublishType==0:
	publishType='Preview'
elif PublishType==1:
	publishType='Alpha'
elif PublishType==2:
	publishType='Beta'
elif PublishType==3:
	publishType='Release'
 
lines[24]=format(" FILEVERSION %d,%d,%d,%s\n" %(MajorVersion,MinorVersion,MaintenanceVersion,BuildNumber))
lines[25]=format(" PRODUCTVERSION %d,%d,%d,%s\n" %(MajorVersion,MinorVersion,MaintenanceVersion,BuildNumber))
lines[42]=format("            VALUE \"FileVersion\", \" %d.%d.%d.%s\"\n" %(MajorVersion,MinorVersion,MaintenanceVersion,BuildNumber))
lines[47]=format("            VALUE \"ProductVersion\", \" %d.%d.%d.%s %s Build-%s\"\n" %(MajorVersion,MinorVersion,MaintenanceVersion,BuildNumber, publishType, BuildDateSignature))

#print(lines[24], end='')
#print(lines[25], end='')
#print(lines[42], end='')
#print(lines[47], end='')
#for line in lines:
#	if 'FILEVERSION' in line:
#		print(line, end='')
#		line='Hello'
#	elif 'PRODUCTVERSION' in line:
#		print(line, end='')
#		line='Hello'
#	elif 'FileVersion' in line:
#		print(line, end='')
#		line='Hello'
#	elif 'ProductVersion' in line:
#		print(line, end='')
#		line='Hello'
#	print(lines)
		
rc_file=open(rc_path, 'w')
for line in lines:
	rc_file.write(line)
rc_file.close()






